<?php
namespace Sdk;
use xmpush\Builder;

use xmpush\Sender;
use xmpush\Constants;

use xmpush\TargetedMessage;

use xmpush\IOSBuilder;

use xmpush\Stats;
use xmpush\Tracer;
include_once(dirname(__FILE__) . '/autoload.php');

class Push
{
    const secret='+MUlhgp8la8eMYRxlu22DA==';
    const pacjage ='com.zjjyy.creditmanager';
    /*
     *  $style   int 推送方式,1,安卓,2,苹果,3,安卓推送打开应用内的某个activity
     *  $aliasList  array,格式为array("1,2,3,4,5,6"),也就是推送的目标别名
     *  $titlse  String     推送标题
     *  $conent  String     推送内容
     *  $payload String     暂时不用
     *  注:因为写的比较仓促,可以将  3  内的跳转到指定activity的参数放在参数列表,以方便调用
     *     也可以将if else 改为switch,此类为举例,完全可以自己构思这个类,我只是举个例子
     * */
    public function pushs($style,$aliasList,$titlse,$conent,$payload="")
    {
        $id = (int)$style;

        $desc = $conent;
        $secret = self::secret;
        $package = self::pacjage;
        if($id == 1){
            //regid
            Constants::setPackage($package);
            Constants::setSecret($secret);
            $title = $titlse;
            $sender = new Sender();
            $message = new Builder();
            $message->title($title);
            $message->description($desc);
            $message->payload($payload); // 对于预定义点击行为，payload会通过点击进入的界面的intent中的extra字段获取，而不会调用到onReceiveMessage方法。
            $message->extra(Builder::notifyEffect, 1); // 此处设置预定义点击行为，1为打开app
            $message->extra(Builder::notifyForeground, 1);
            $message->notifyId(1);
            $message->build();
//            $targetMessage2 = new TargetedMessage();
//            $targetMessage2->setTarget('tag', TargetedMessage::TARGET_TYPE_ALIAS);
//            $targetMessage2->setMessage($message);
//            $targetMessageList = array( $targetMessage2);
            return $sender->send($message,$aliasList)->getRaw();
        }
        else if($id ==2)
        {
            //推送所有

            Constants::setPackage($package);
            Constants::setSecret($secret);
            $title = $titlse;
            $sender = new Sender();
            $message = new Builder();
            $message->title($title);
            $message->description($desc);
            $message->payload($payload); // 对于预定义点击行为，payload会通过点击进入的界面的intent中的extra字段获取，而不会调用到onReceiveMessage方法。
            $message->extra(Builder::notifyEffect, 1); // 此处设置预定义点击行为，1为打开app
            $message->extra(Builder::notifyForeground, 1);
            $message->notifyId(1);
            $message->build();
            return $sender->broadcastAll($message)->getRaw();
        }else if($id == 3){
            //别名推送
            Constants::setPackage($package);
            Constants::setSecret($secret);
            $title = $titlse;
            $sender = new Sender();
            $message = new Builder();
            $message->title($title);
            $message->description($desc);
            $message->passThrough(0);
            $message->payload($payload); // 对于预定义点击行为，payload会通过点击进入的界面的intent中的extra字段获取，而不会调用到onReceiveMessage方法。
            $message->extra(Builder::notifyEffect, 1); // 此处设置预定义点击行为，1为打开app,2为打开应用内的activity
            $message->extra(Builder::notifyForeground, 1);
            $message->notifyId(0);
            $message->build();
//            $targetMessage2 = new TargetedMessage();
//            $targetMessage2->setTarget('tag', TargetedMessage::TARGET_TYPE_ALIAS);
//            $targetMessage2->setMessage($message);
//            $targetMessageList = array( $targetMessage2);
            return   $sender->sendToAlias($message,$aliasList)->getRaw();
        }
      //  print_r($sender->sendToAliases($message,$aliasList)->getRaw());
    }

}

?>